package chapter1.dataabstraction.example;

import edu.princeton.cs.algs4.Counter;
import edu.princeton.cs.algs4.StdRandom;

/**
 * @author quanlinlin on 2018/11/4 14:31.
 * @version 1.0
 */
public class FlipsMax {

    public static void main(String[] args) {
        int T = Integer.parseInt(args[0]);
        Counter heads = new Counter("heads");
        Counter tails = new Counter("tails");
        for (int i = 0; i < T; i++) {
            if (StdRandom.bernoulli(0.5)) {
                heads.increment();
            } else {
                tails.increment();
            }
        }
        if (heads.tally() == tails.tally()) {
            System.out.println("Tie");
        } else {
            System.out.println(max(heads, tails) + " wins");
        }
    }

    private static Counter max(Counter x, Counter y) {
        if (x.tally() > y.tally()) {
            return x;
        }
        return y;
    }
}
